package artiko.ai.posizionamento.rafforzamentoIniziale;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Collection;

import alice.tuprolog.*;
import alice.tuprologx.pj.model.Clause;




public class TuPrologProva {
public static void main(String[] args) throws InvalidTheoryException, InvalidLibraryException, FileNotFoundException, IOException, NoSolutionException, NoMoreSolutionException, MalformedGoalException{
	
	Prolog engine=new Prolog();
	
	Theory theory = new Theory(new FileInputStream("base.pl"));
	try {
	engine.setTheory(theory);
	} catch(InvalidTheoryException ex){
	}
	
	// faccio la query
	SolveInfo info = engine.solve(
		    "terrAttaccante(X)."
		);
		while(info.isSuccess()) {
		    Term solution = info.getSolution();
		    		   
			String mossa = null;
		    if(solution.toString().length() == 18){
			    mossa = solution.toString().substring(16, 17);}
			    else{
			    	 mossa = solution.toString().substring(16, 18);
			    }
		    System.out.println(mossa);
		    
		    // se ci sono altri risultati vado avanti
		    if(engine.hasOpenAlternatives())
		        info = engine.solveNext();
		    else
		        break;
		}
	
	
}
}
